<?php
class LoginAction extends Action{
    public function login(){
        $this->display();
    }
    //登录
    public function doLogin(){
        //接受值
        //判断用户是否存在
        //存在，允许登录
        //不存在，显示错误
        $admin=$_POST['admin'];
        $password=$_POST['password'];
        $Admin=M('Admin');
        $where['admin']=$admin;
        $where['password']=$password;
        $arr=$Admin->field('admin')->where($where)->find();
        if($arr){
            $_SESSION['admin']=$admin;
            $this->success('登录成功',U('Index/index'));
        }else{
            $this->error('用户不存在！');
        }
    }
    //退出
    public function doLogout(){
        $_SESSION=array();
            if(isset($_COOKIE[session_name()])){
                setcookie(session_name(),'',time()-1,'/');
            }
        session_destroy();
        $this->redirect('Index/index');
    }
}

?>